﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;

namespace TeamsPortal.Security
{
    public interface IRoleService
    {
        bool IsUserInRole(string userName, string roleName);
        string[] GetAll();
        string[] GetUsersInRole(string roleName);
        void Create(string name);
        bool Delete(string name);
        void AddUserToRole(string username, string roleName);
        void RemoveUserFromRole(string userName, string roleName);
    }

    public class RoleService : IRoleService
    {
        public bool IsUserInRole(string userName, string roleName)
        {
            return Roles.IsUserInRole(userName, roleName);
        }

        public string[] GetAll()
        {
            string[] result = Roles.GetAllRoles();
            return result;
        }

        public string[] GetUsersInRole(string roleName)
        {
            string[] result = Roles.GetUsersInRole(roleName);
            return result;
        }

        public void Create(string name)
        {
            Roles.CreateRole(name);
        }

        public bool Delete(string name)
        {
            bool result = Roles.DeleteRole(name, true);
            return result;
        }

        public void AddUserToRole(string username, string roleName)
        {
            Roles.AddUserToRole(username, roleName);
        }

        public void RemoveUserFromRole(string userName, string roleName)
        {
            Roles.RemoveUserFromRole(userName, roleName);
        }
    }
}
